package com.controller;

import com.pojo.Customer;
import com.pojo.Student;
import com.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class CustomerController {
    @Autowired
    CustomerService service;
    @Autowired
    Customer customer;
    @Autowired
    Student student;
    @Autowired
    List<Customer> list;

    @RequestMapping("query")
    public List<Customer> query(){
        list = service.query();
        return list;
    }

    @RequestMapping("queryById")
    public Customer queryById(){
        customer=service.queryById(3);
        return customer;
    }

    @RequestMapping("add")
    public String add(Customer customer, Student student){
        customer.setUsername("李明");
        customer.setPhone("132131");
        customer.setJobs("教授");
        student.setUsername("小芳");
        student.setAge("11");
        service.add(customer,student);
        return "添加成功";
    }

    @RequestMapping("dell")
    public String dell(){
        service.del(1);
        return "删除成功";
    }

    @RequestMapping("update")
    public String update(Customer customer) {
        customer.setId("2");
        customer.setUsername("小李");
        customer.setPhone("132131");
        customer.setJobs("教授");
        service.update(customer);
        return "修改成功";
    }

}
